Skip to content

fix: handle falsy parameter values in _parse#876

Merged
bakerkretzmar merged 1 commit intotighten:2.xfrom
pataar:fix/falsy-parameter-values
Mar 5, 2026
Merged

fix: handle falsy parameter values in _parse#876
bakerkretzmar merged 1 commit intotighten:2.xfrom
pataar:fix/falsy-parameter-values

Conversation

@pataar
Copy link
Copy Markdown
Contributor

@pataar pataar commented Mar 5, 2026

Summary

  • Fixes a bug where route('posts.show', { post: 0 }) would incorrectly wrap params to { post: { post: 0 } } because the truthiness check !params[segments[0].name] treats 0 as falsy
  • Replaced with !params.hasOwnProperty(segments[0].name) to check for key presence instead of truthiness
  • Added a test case for this scenario

Example

// Route: 'posts/{post}'
route('posts.show', { post: 0 });
// Before: !params['post'] → !0 → true, so params gets wrapped to { post: { post: 0 } }
// After:  !params.hasOwnProperty('post') → false, so params stays as { post: 0 } ✓

Test plan

  • New test: can handle an object parameter with a falsy value for the segment name
  • All existing tests pass (npx vitest --typecheck)

…sence in _parse

The check `!params[segments[0].name]` used truthiness to determine if a
parameter key was present, causing falsy-but-valid values like `0` to be
treated as missing. For example, `route('posts.show', { post: 0 })` would
incorrectly wrap params to `{ post: { post: 0 } }` because `!0` is `true`.

Replaced with `!params.hasOwnProperty(segments[0].name)` to check for key
presence instead.
@bakerkretzmar
Copy link
Copy Markdown
Collaborator

Thanks! 🙏

@bakerkretzmar bakerkretzmar merged commit de3c44a into tighten:2.x Mar 5, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants